package com.nowcoder.community.controller;

import com.nowcoder.community.annotation.LoginRequire;
import com.nowcoder.community.service.MessageService;
import com.nowcoder.community.util.JsonBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("message")
public class MessageController {
    @Autowired
    MessageService messageService;


    @LoginRequire
    @ResponseBody
    @PostMapping("/send")
    public JsonBody sendLetter(String toName, String content) {
        if (toName == null || toName.isEmpty() || content == null || content.isEmpty()) {
            return JsonBody.error("发送失败, 参数错误.");
        }

        return messageService.sendLetter(toName, content);
    }
}
